import random

print("猜数字游戏开始")

result = random.randint(1, 100)
maxNum = 100
maxMin = 1
while True:
    num = input("输入一个数字：")
    try:
        num = int(num)
    except ValueError:
        print("输入有误，请数字在{}-{}之间".format(maxMin, maxNum), end="")
        continue
    if num >= maxNum or num <= maxMin:
        print("输入范围有误，请数字在{}-{}之间".format(maxMin, maxNum), end="")
        continue
    if num > result:
        maxNum = num
        print("猜大了，请在{}-{}之间再".format(maxMin, maxNum), end="")
    elif num < result:
        maxMin = num
        print("猜小了，请在{}-{}之间再".format(maxMin, maxNum), end="")
    else:
        print("猜对了，数字就是：{}".format(result))
        break
